﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;

public partial class ManageCenter_ViewSystemRecord : System.Web.UI.Page
{
    SystemItems systemitem = new SystemItems();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PageBind();
            ddlpages.Items.Clear();
            for (int i = 1; i <= gvshowrecord.PageCount; i++)
            {
                ddlpages.Items.Add("第" + i + "页");
            }
        }
    }
    protected void PageBind()
    {
        DataSet ds = systemitem.GetAllSystemItems();
        gvshowrecord.DataSource = ds;
        gvshowrecord.DataBind();
        if (gvshowrecord.PageIndex == 0 && gvshowrecord.PageCount == 1)
        {
            btnfirstpage.Enabled = false;
            btnlastpage.Enabled = false;
            btnnextpage.Enabled = false;
            btnprepage.Enabled = false;
        }
        else if (gvshowrecord.PageIndex == 0 && gvshowrecord.PageCount > 1)
        {
            btnfirstpage.Enabled = false;
            btnlastpage.Enabled = true;
            btnnextpage.Enabled = true;
            btnprepage.Enabled = false;
        }
        else if (gvshowrecord.PageIndex > 0 && gvshowrecord.PageIndex < gvshowrecord.PageCount - 1)
        {
            btnfirstpage.Enabled = true;
            btnlastpage.Enabled = true;
            btnnextpage.Enabled = true;
            btnprepage.Enabled = true;
        }
        else if (gvshowrecord.PageIndex == gvshowrecord.PageCount - 1)
        {
            btnfirstpage.Enabled = true;
            btnlastpage.Enabled = false;
            btnnextpage.Enabled = false;
            btnprepage.Enabled = true;
        }
    }
    protected void btnnextpage_Click(object sender, EventArgs e)
    {
        int index = gvshowrecord.PageIndex;
        gvshowrecord.PageIndex = index + 1;
        PageBind();
    }
    protected void btnprepage_Click(object sender, EventArgs e)
    {
        int index = gvshowrecord.PageIndex;
        gvshowrecord.PageIndex = index - 1;
        PageBind();
    }
    protected void btnfirstpage_Click(object sender, EventArgs e)
    {
        gvshowrecord.PageIndex = 0;
        PageBind();
    }
    protected void btnlastpage_Click(object sender, EventArgs e)
    {
        gvshowrecord.PageIndex = gvshowrecord.PageCount - 1;
        PageBind();
    }
    protected void ddlpages_SelectedIndexChanged(object sender, EventArgs e)
    {
        int index = Convert.ToInt32(ddlpages.SelectedItem.ToString().Substring(1, 1));
        gvshowrecord.PageIndex = index - 1;
        PageBind();
    }
}
